﻿@model Dictionary<string, string>
@{
    string vietnamese = "àáạãảắằẵẳặấầậẫẩùúũụủữừứửựòóỏõọớờỡởợốồộổỗèéẻẽẹếềểễệìíỉịĩăâươêôđÀÁẠÃẢẮẰẴẲẶẤẦẬẪẨÙÚŨỤỦỮỪỨỬỰÒÓỎÕỌỚỜỠỞỢỐỒỘỔỖÈÉẺẼẸẾỀỂỄỆÌÍỈỊĨĂÂƯƠÊÔĐỳýỷỹỵÝỶỲỸỴ";
    string textpattern = string.Format("/^[a-zA-Z0-9.,{0} ]+$/", vietnamese);
    string numberpattern = "/^[0-9., ]+$/";
    string text = Model["Text"];
    string ngModel = Model["Model"];
    string name = Model["Name"];
    string input = Model.ContainsKey("Input") ? Model["Input"] : "Text";
    string minlength = Model.ContainsKey("MinLength") ? Model["MinLength"] : "0";
    string minlengthmsg = Model.ContainsKey("MinLengthMsg") ? Model["MinLengthMsg"] : string.Format("Tối thiểu {0} ký tự", minlength);
    string maxlength = Model.ContainsKey("MaxLength") ? Model["MaxLength"] : "250";
    string maxlengthmsg = Model.ContainsKey("MaxLengthMsg") ? Model["MaxLengthMsg"] : string.Format("Tối đa {0} ký tự",maxlength);
    string pattern = input == "Text" ? textpattern : numberpattern;
    string patternmsg = Model.ContainsKey("PatternMsg") ? Model["PatternMsg"] : "Ký tự không hợp lệ";
    string blur = Model.ContainsKey("Blur") ? Model["Blur"] : string.Empty;
    string disabled = Model.ContainsKey("Disabled") ? Model["Disabled"] : string.Empty;
    string keypress = Model.ContainsKey("KeyPress") ? Model["KeyPress"] : string.Empty;
}
<label>@text</label>
<div class="form-group">
    <input ng-model="@ngModel" name="@name" type="text" class="form-control" ng-minlength=@minlength ng-maxlength=@maxlength ng-pattern="@pattern" ng-blur="@blur" ng-disabled="@disabled" ng-keypress="@keypress"/>
    <div class="error-container" 
         ng-show="form.@name.$dirty && form.@name.$invalid">
        <small class="error" 
             ng-show="form.@name.$error.minlength"><p style="color:red"><b>@minlengthmsg</b></p> 
        </small>
        <small class="error" 
             ng-show="form.@name.$error.maxlength"><p style="color:red"><b>@maxlengthmsg</b></p> 
        </small>
        <small class="error" 
             ng-show="form.@name.$error.pattern"><p style="color:red"><b>@patternmsg</b></p> 
        </small>
    </div>
</div>
